<?php
include ("../main/inc/global.inc.php");

require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
require_once (api_get_path(LIBRARY_PATH).'usermanager.lib.php');
require_once (api_get_path(CONFIGURATION_PATH).'profile.conf.php');

api_block_anonymous_users(); // only users who are logged in can proceed

// Top part of the HTML
Display :: display_header('File List');
?>

<?php
$link = mysql_connect("localhost", "root", "root");
mysql_select_db("dokeos_main", $link);

if (isset($_POST['sharefile_fileId']) && isset($_POST['sharefile_userId']) )
{
		
	$user_access=$_POST['sharefile_userAccess'];
	$is_owner=0;
	$can_edit=0;
	$can_read=0;
	switch ($user_access) {
		case "isOwner":
			$is_owner=1; $can_edit=1; $can_read=1;
			break;
		case "canEdit":
			$is_owner=0; $can_edit=1; $can_read=1;
			break;
		case "canRead":
			$is_owner=0; $can_edit=0; $can_read=1;
			break;
	}
    $sql="INSERT INTO file_user (fileId, userid, isowner, canread, canedit)
    VALUES
    ('$_POST[sharefile_fileId]','$_POST[sharefile_userId]','$is_owner','$can_read', '$can_edit')";
    $result = mysql_query($sql, $link);
}

if($result){
	echo "File shared to user " . $_POST['sharefile_userId'];
} else {
	echo "File sharing is not successful";
}

mysql_close($link);


?>

<?php
// Footer
Display :: display_footer();
?>
